##############################################################
## MOD Title: phpBB Sportsuite
## MOD Author: Creomire < ghughes@creomire.com > (Garry Hughes) http://www.olympus.creomire.com
## MOD Description: A feature rich add-on for sports related boards
##
## MOD Version: 0.2.1a
##
## Installation Level: Easy
## Installation Time: 5 Minutes
## Files To Edit: 4
##			includes/functions.php
##			language/en/common.php
##			styles/prosilver/template/overall_footer.html
##			styles/prosilver/template/overall_header.html
##
## Included Files: 60
##			includes/mods/index.htm
##			includes/mods/sportsuite/constants.php
##			includes/mods/sportsuite/index.htm
##			includes/mods/sportsuite/sportsuite.php
##			includes/mods/sportsuite/statistics.php
##			language/en/mods/index.htm
##			language/en/mods/sportsuite/common.php
##			language/en/mods/sportsuite/cp.php
##			language/en/mods/sportsuite/index.htm
##			language/en/mods/sportsuite/stats.php
##			sportsuite/common.php
##			sportsuite/index.htm
##			sportsuite/cp/common.php
##			sportsuite/cp/index.php
##			sportsuite/cp/index_gen_config.php
##			sportsuite/cp/index_league_config.php
##			sportsuite/cp/index_team_config.php
##			sportsuite/cp/sportsbook.php
##			sportsuite/cp/sportsbook_config.php
##			sportsuite/cp/sportsbook_fixtures.php
##			sportsuite/cp/sportsbook_fixtures_edit.php
##			sportsuite/cp/sportsbook_history.php
##			sportsuite/cp/sportsbook_results.php
##			sportsuite/cp/sportsbook_retro_fixtures.php
##			sportsuite/cp/sportsbook_tools.php
##			sportsuite/sportsbook/fixtures.php
##			sportsuite/sportsbook/index.htm
##			sportsuite/sportsbook/results.php
##			sportsuite/sportsbook/tables.php
##			sportsuite/sportsbook/stats/index.htm
##			sportsuite/sportsbook/stats/league_table.php
##			sportsuite/sportsbook/stats/user_table.php
##			styles/prosilver/template/mods/index.htm
##			styles/prosilver/template/mods/sportsuite/index.htm
##			styles/prosilver/template/mods/sportsuite/sbook_nav.html
##			styles/prosilver/template/mods/sportsuite/sportsbook_body.html
##			styles/prosilver/template/mods/sportsuite/sportsbook_footer.html
##			styles/prosilver/template/mods/sportsuite/sportsbook_header.html
##			styles/prosilver/template/mods/sportsuite/cp/cp_footer.html
##			styles/prosilver/template/mods/sportsuite/cp/cp_header.html
##			styles/prosilver/template/mods/sportsuite/cp/edit_league.html
##			styles/prosilver/template/mods/sportsuite/cp/edit_team.html
##			styles/prosilver/template/mods/sportsuite/cp/index.htm
##			styles/prosilver/template/mods/sportsuite/cp/index_body.html
##			styles/prosilver/template/mods/sportsuite/cp/index_gen_config.html
##			styles/prosilver/template/mods/sportsuite/cp/index_league_config.html
##			styles/prosilver/template/mods/sportsuite/cp/index_nav.html
##			styles/prosilver/template/mods/sportsuite/cp/index_team_config.html
##			styles/prosilver/template/mods/sportsuite/cp/sportsbook_body.html
##			styles/prosilver/template/mods/sportsuite/cp/sportsbook_edit_fixtures.html
##			styles/prosilver/template/mods/sportsuite/cp/sportsbook_fixtures.html
##			styles/prosilver/template/mods/sportsuite/cp/sportsbook_history.html
##			styles/prosilver/template/mods/sportsuite/cp/sportsbook_nav.html
##			styles/prosilver/template/mods/sportsuite/cp/sportsbook_results.html
##			styles/prosilver/template/mods/sportsuite/cp/sportsbook_retro_fixtures.html
##			styles/prosilver/template/mods/sportsuite/cp/sportsbook_tools.html
##			styles/prosilver/template/mods/sportsuite/sportsbook/index.htm
##			styles/prosilver/template/mods/sportsuite/sportsbook/results_body.html
##			styles/prosilver/template/mods/sportsuite/sportsbook/tables_body.html
##			sportsbook.php
##
## License: http://opensource.org/licenses/gpl-license.php GNU General Public License v2
##############################################################
## Author Notes:
## This is ALPHA software. You should only install this software on your board if you are comfortable 
## editing php files and especially your database.
##
## For upgrades from previous versions, please see contrib folder.
##
##############################################################
## History:
##  (dd-mm-yyyy)
##   20-07-2007 - version 0.2.1a
##	- Minor bug fix
##
##   20-07-2007 - version 0.2.1
##	- Added overall stats to league tables
##	- Removed "confirm fixture" facility (obsolete)
##	- Added retrospective results facility
##	- Added minute options to autoclose configuration
##	- User predictions now only update if they have changed (saves db queries)
##	- Added filter options to fixtures page
##	- Stats and information added to admin welcome page
##	- Various minor bug fixes and tweaks
##
##   17-07-2007 - version 0.2.0
##	- Re-write of the fixture addition system, allowing multiple additions at once
##	- Fixed typos in install file
##
##   15-07-2007 - version 0.1.2
##	- Fixed a bug in team statistics calculation
##	- New team statistics database table added, saving repeat calculations
##	- Fixed bug where leagues without teams where visible to "public"
##	- Fixed small bug with user table (leaderboard)
##	- Added ability to "mass add" teams, as opposed to one at a time
##	- Added autoclose facility for fixtures
##	- Automatic removal of "correct score" details if admin doesn't set correct score fixtures
##		or users haven't managed any correct scores
##	- Fixed bug in sportsbook_fixtures.php where league with no teams causes errors
##	- Added facility to recalculate league statistics
##	- Added reset options
##	- Various minor bug fixes and tweaks
##
##   13-07-2007 - version 0.1.1
##	- Small bug fix with Sportsuite's use of request_var() function
##
##   12-07-2007 - version 0.1.0
##	- Integration with phpbb`s native cache system
##	- Added ability for admin to set a home/away (1-2) fixture
##	- Explanation of league table column abbreviations added.
##
##   09-07-2007 - version 0.0.2
##	- Mod version added to footers
##	- Fixed bug in results.php were outstanding fixtures were causing problems
##	- Added ability to toggle fail points on and off.
##	- Trigger user statistics re-build after points system has been changed in sportsbook config.
##
##   08-07-2007 - version 0.0.1
##	- First Alpha release
##############################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
##############################################################

#
#-----[ SQL ]------------------------------------------
#
CREATE TABLE `phpbb_sportsuite_config` (
  `config_name` varchar(255) collate utf8_bin NOT NULL default '',
  `config_value` varchar(255) collate utf8_bin NOT NULL default '',
  PRIMARY KEY  (`config_name`)
);

INSERT INTO `phpbb_sportsuite_config` VALUES (0x73626f6f6b5f656e61626c6564, 0x31);
INSERT INTO `phpbb_sportsuite_config` VALUES (0x73626f6f6b5f6e616d65, 0x53706f727473626f6f6b);
INSERT INTO `phpbb_sportsuite_config` VALUES (0x73626f6f6b5f726573756c745f706f696e7473, 0x33);
INSERT INTO `phpbb_sportsuite_config` VALUES (0x73626f6f6b5f73636f72655f706f696e7473, 0x35);
INSERT INTO `phpbb_sportsuite_config` VALUES (0x73626f6f6b5f666978747572655f74696d65, 0x3534303030);
INSERT INTO `phpbb_sportsuite_config` VALUES (0x73626f6f6b5f666978747572655f64617973, 0x3331);
INSERT INTO `phpbb_sportsuite_config` VALUES (0x73626f6f6b5f74696d655f696e6372656d656e7473, 0x31);
INSERT INTO `phpbb_sportsuite_config` VALUES (0x73626f6f6b5f757365725f73746174735f6c696d6974, 0x3135);
INSERT INTO `phpbb_sportsuite_config` VALUES (0x73626f6f6b5f64656661756c745f666978747572655f74797065, 0x31);
INSERT INTO `phpbb_sportsuite_config` VALUES (0x73626f6f6b5f706173745f666978747572655f6c696d6974, 0x32363738343030);
INSERT INTO `phpbb_sportsuite_config` VALUES (0x73706f727473756974655f76657273696f6e, 0x7665722e20302e322e3161);
INSERT INTO `phpbb_sportsuite_config` VALUES (0x73626f6f6b5f6661696c5f706f696e74735f6f6e, 0x31);
INSERT INTO `phpbb_sportsuite_config` VALUES (0x73626f6f6b5f666978747572655f6175746f636c6f7365, 0x2d31);

CREATE TABLE `phpbb_sportsuite_leagues` (
  `league_id` smallint(5) NOT NULL auto_increment,
  `league_name` varchar(30) collate utf8_bin NOT NULL default '',
  `league_type` tinyint(2) NOT NULL default '0',
  `league_points_win` tinyint(2) NOT NULL default '3',
  `league_points_draw` tinyint(2) NOT NULL default '1',
  PRIMARY KEY  (`league_id`)
);

CREATE TABLE `phpbb_sportsuite_sbook_fixtures` (
  `fixture_id` int(11) NOT NULL auto_increment,
  `league_id` smallint(5) NOT NULL default '0',
  `fixture_type` tinyint(2) NOT NULL default '0',
  `fixture_user_id` mediumint(8) NOT NULL default '0',
  `fixture_time` int(11) NOT NULL default '0',
  `team_id_home` smallint(5) NOT NULL default '0',
  `team_id_away` smallint(5) NOT NULL default '0',
  `fixture_score_home` smallint(5) NOT NULL default '-1',
  `fixture_score_away` smallint(5) NOT NULL default '-1',
  `fixture_process_user_id` mediumint(8) NOT NULL default '-1',
  PRIMARY KEY  (`fixture_id`),
  KEY `league_id` (`league_id`),
  KEY `fixture_type` (`fixture_type`)
);

CREATE TABLE `phpbb_sportsuite_sbook_user_bets` (
  `user_id` mediumint(8) NOT NULL default '0',
  `fixture_id` mediumint(11) NOT NULL default '0',
  `bet_home_score` tinyint(3) NOT NULL default '0',
  `bet_away_score` tinyint(3) NOT NULL default '0',
  KEY `user_id` (`user_id`)
);

CREATE TABLE `phpbb_sportsuite_sbook_user_stats` (
  `user_id` mediumint(8) NOT NULL default '0',
  `stats_predictions` int(11) NOT NULL default '0',
  `stats_fails` int(11) NOT NULL default '0',
  `stats_results` int(11) NOT NULL default '0',
  `stats_scores` int(11) NOT NULL default '0',
  `stats_points` int(11) NOT NULL default '0',
  `stats_superceded` tinyint(1) NOT NULL default '0',
  PRIMARY KEY  (`user_id`)
);

CREATE TABLE `phpbb_sportsuite_teams` (
  `team_id` smallint(5) NOT NULL auto_increment,
  `team_name` varchar(30) collate utf8_bin NOT NULL default '',
  `league_id` smallint(5) NOT NULL default '0',
  PRIMARY KEY  (`team_id`)
);

CREATE TABLE `phpbb_sportsuite_sbook_hth_team_stats` (
  `team_id` smallint(5) NOT NULL,
  `team_points` mediumint(7) NOT NULL,
  `team_gd` mediumint(7) NOT NULL,
  `team_hp` smallint(5) NOT NULL,
  `team_hw` smallint(5) NOT NULL,
  `team_hl` smallint(5) NOT NULL,
  `team_hd` smallint(5) NOT NULL,
  `team_hf` mediumint(7) NOT NULL,
  `team_ha` mediumint(7) NOT NULL,
  `team_ap` smallint(5) NOT NULL,
  `team_aw` smallint(5) NOT NULL,
  `team_al` smallint(5) NOT NULL,
  `team_ad` smallint(5) NOT NULL,
  `team_af` mediumint(7) NOT NULL,
  `team_aa` mediumint(7) NOT NULL,
  UNIQUE KEY `team_id` (`team_id`)
);

#
#-----[ COPY ]------------------------------------------
#
copy root/*.* to *.*

#
#-----[ OPEN ]------------------------------------------
#

includes/functions.php

#
#-----[ FIND ]------------------------------------------
#

	// The following assigns all _common_ variables that may be used at any point in a template.

#
#-----[ BEFORE, ADD ]------------------------------------------
#

	// sportsuite mod
	// grab sitewide sportsuite vars if required
	if(!defined('IN_SPORTSUITE'))
	{
		global $table_prefix;
		
		include("{$phpbb_root_path}includes/mods/sportsuite/constants.$phpEx");
		// grab the bare config values
		$sql = 'SELECT config_name, config_value
			FROM ' . SPORTSUITE_CONFIG_TABLE . "
			WHERE config_name IN('sbook_enabled','sbook_name')";
			
		$result = $db->sql_query($sql);
		
		while ($row = $db->sql_fetchrow($result))
		{
			$sportsuite_config[$row['config_name']] = $row['config_value'];
		}
		$db->sql_freeresult($result);
		
		$template->assign_vars(array(
			'S_SBOOK_ENABLED' 		=> ($sportsuite_config['sbook_enabled']) ? true : false,
			'SBOOK_NAME' 			=> $sportsuite_config['sbook_name'])
		);
	}
	// end sportsuite mod

#
#-----[ FIND ]------------------------------------------
#

		'U_RESTORE_PERMISSIONS'	=> ($user->data['user_perm_from'] && $auth->acl_get('a_switchperm')) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=restore_perm') : '',

#
#-----[ AFTER, ADD ]------------------------------------------
#

		// sportsuite mod
		'U_SPORTSBOOK'			=> append_sid("{$phpbb_root_path}sportsbook.$phpEx"),
		'U_SPORTSUITE_CP' 		=> ($auth->acl_get('a_') && $user->data['is_registered']) ? append_sid("{$phpbb_root_path}sportsuite/cp/index.$phpEx") : '',
		// end sportsuite mod

#
#-----[ FIND ]------------------------------------------
#

		'S_NEW_PM'				=> ($s_privmsg_new) ? 1 : 0,

#
#-----[ AFTER, ADD ]------------------------------------------
#

		// sportsuite mod
		'S_SPORTSUITE_ADMIN' 	=> ($auth->acl_get('a_') && $user->data['is_registered']) ? true : false,
		// end sportsuite mod

#
#-----[ OPEN ]------------------------------------------
#

language/en/common.php

#
#-----[ FIND ]------------------------------------------
#

));

?>

#
#-----[ BEFORE, ADD ]------------------------------------------
#

	// spotsuite mod
	'SPORTSUITE' 	=> 'phpbb Sportsuite',
	'SPORTSUITE_CP' => 'Sportsuite Control Panel',

#
#-----[ OPEN ]------------------------------------------
#

styles/prosilver/template/overall_footer.html

#
#-----[ FIND ]------------------------------------------
#

		<!-- IF U_ACP --><br /><strong><a href="{U_ACP}">{L_ACP}</a></strong><!-- ENDIF -->
#
#-----[ AFTER, ADD ]------------------------------------------
#

		<!-- IF S_SPORTSUITE_ADMIN --><br /><strong><a href="{U_SPORTSUITE_CP}" title="{L_SPORTSUITE_CP}">{L_SPORTSUITE_CP}</a></strong><!-- ENDIF -->

#
#-----[ OPEN ]------------------------------------------
#

styles/prosilver/template/overall_header.html

#
#-----[ FIND ]------------------------------------------
#

</head>

#
#-----[ BEFORE, ADD ]------------------------------------------
#

{SBOOK_JAVA}

#
#-----[ FIND ]------------------------------------------
#

				<li class="rightside">
					<a href="{U_FAQ}" title="{L_FAQ_EXPLAIN}" class="icon-faq">{L_FAQ}</a>&nbsp;

#
#-----[ IN-LINE, FIND ]------------------------------------------
#

<li class="rightside">

#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------
#

<!-- IF S_SBOOK_ENABLED --><a href="{U_SPORTSBOOK}" title="{SBOOK_NAME}" class="icon-members">{SBOOK_NAME}</a>&nbsp; <!-- ENDIF -->

#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#

#
#-----[ EOM ]------------------------------------------
#
